package com.xin.data.simbapesa.dialog;

import android.content.Context;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.xin.data.simbapesa.R;
import com.xin.data.simbapesa.adapter.AccountAdapter;
import com.xin.data.simbapesa.base.BaseDialog;
import com.xin.data.simbapesa.databinding.SimbaAccountSubmitBinding;
import com.xin.data.simbapesa.obj.SimbaAccountItem;
import com.xin.data.simbapesa.utils.ResUtils;
import com.xin.data.simbapesa.utils.ViewUtils;
import com.xin.data.simbapesa.view.SimbaSpaceItemDecoration;

import java.util.ArrayList;
import java.util.List;

public class SubmitDialog extends BaseDialog<SimbaAccountSubmitBinding> {


    AccountAdapter adater;
    List<SimbaAccountItem> dataList;


    public SubmitDialog(@NonNull Context context) {
        super(context);
    }

    public SubmitDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected SubmitDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected SimbaAccountSubmitBinding initViewBinding(LayoutInflater inflater) {
        return SimbaAccountSubmitBinding.inflate(inflater);
    }

    @Override
    protected void initView() {
        binding.tvOk.setOnClickListener(v -> {
            ViewUtils.viewScale(v);
            dismiss();
            if (onBtnClickListener != null) {
                onBtnClickListener.btnOnClickOk();
            }
        });
        binding.tvClose.setOnClickListener(v -> {
            ViewUtils.viewScale(v);
            if (onBtnClickListener != null) {
                onBtnClickListener.btnOnClickColse();
            }
            dismiss();
        });
        dataList = new ArrayList<>();
        adater = new AccountAdapter(dataList);
        adater.setSummit(true);
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        binding.recyclerView.setLayoutManager(manager);
        int d = ResUtils.d(R.dimen.dp_6);
        binding.recyclerView.addItemDecoration(new SimbaSpaceItemDecoration(d, d, getContext()));
        binding.recyclerView.setAdapter(adater);
    }

    public void setData(List<SimbaAccountItem> list) {
        if (list != null && !list.isEmpty()) {
            dataList.clear();
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).isData()) {
                    list.get(i).setDelete(false);
                    list.get(i).setShowName(false);
                    dataList.add(list.get(i));
                }
            }
            adater.updateAllData();
        }
    }


}
